package com.florida.codigo;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.*;

public class Login extends JFrame implements KeyListener, ActionListener{

	JTextField txtlogin = new JTextField("");
	JPasswordField key = new JPasswordField("");
	JButton Aceptar = new JButton("Aceptar");
	JButton Cancelar = new JButton("Cancelar");
	
	//******************************************CONSTRUCTORES*************************************************//
	public Login(){
		super("      Login      ");
		ventana();
	}
	
	//***********************************************METODOS**************************************************//
	
	//Cargo la ventana
	public void ventana(){
		
		this.setLayout(null);
		//Cargo el logo de la ventana
		this.setIconImage(new ImageIcon("src/com/florida/imagenes/f.gif").getImage());
		//Guardo las dimensiones de la pantalla
		Dimension pantalla = Toolkit.getDefaultToolkit().getScreenSize();
		this.setBounds((int)(pantalla.getWidth()*0.25), (int)(pantalla.getHeight()*0.25), 300, 190);
		this.setResizable(true);
		
		//interior frame:
		
		JLabel login = new JLabel("Login:");
		login.setBounds(20, 20, 100, 25);
		this.add(login);
		txtlogin.setBounds(105, 20, 150, 25);
		this.add(txtlogin);
		
		JLabel password = new JLabel("Password:");
		password.setBounds(20, 50, 200, 25);
		this.add(password);
		key.setBounds(105, 50, 150, 25);
		key.addKeyListener(this);
		this.add(key);
		
		Aceptar.setBounds(50, 100, 100, 25);
		Aceptar.addActionListener(this);
		this.add(Aceptar);
		
		Cancelar.setBounds(155, 100, 100, 25);
		Cancelar.addActionListener(this);
		this.add(Cancelar);
  
		//close interior frame
		
		ImageIcon imagen = new ImageIcon("src/com/florida/imagenes/fondo.png");
	    JLabel etiqueta = new JLabel(imagen);
	    etiqueta.setBounds(0, 0, (int)(pantalla.getWidth()*0.75), (int)(pantalla.getHeight()*0.75));
	    getContentPane().add(etiqueta);
		
		this.setVisible(true);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	}
	
	
	//************************************************MAIN***************************************************//
	public static void main(String args []){
		Login a = new Login();
	}

	
	//*********************************************IMPLEMENTS***********************************************//
	
	//Cuando pulsas una tecla.
	@Override
	public void keyPressed(KeyEvent e) {
		if(e.getKeyCode()==10){
			VentanaPrincipal inicio = new VentanaPrincipal();
		}
	}

	@Override
	public void keyReleased(KeyEvent e) {}

	@Override
	public void keyTyped(KeyEvent e) {}
	
	//Para los botones.
	@Override
	public void actionPerformed(ActionEvent arg0) {
		if(arg0.getSource().equals(Aceptar)){
			VentanaAdministrador uno = new VentanaAdministrador();
		}	
		if(arg0.getSource().equals(Cancelar)){
			this.dispose();
			VentanaPrincipal inicio = new VentanaPrincipal();
		}
		
	}

	
   
}
